package com.mooer.utils.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.view.KeyEvent;

public class DialogUtils {
	
	public static void showExitDialog(final Activity ctx)
	{
		new AlertDialog.Builder(ctx).setTitle("退出").setMessage("是否退出？").setPositiveButton("是", new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int which)
			{
				dialog.dismiss();
				ctx.finish();
			}
		}).setNegativeButton("否", new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int which)
			{
				dialog.dismiss();
			}
		}).create().show();
	}

	
	public static void showInfoDialog(Context context, String info)
	{
		new AlertDialog.Builder(context).setTitle("提示").setMessage(info)
			.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) 
				{
					dialog.dismiss();
				}
			}).show();
	}
	
	/*
	 * 网络交互时显示的Dialog
	 */
	public static ProgressDialog showDialog(Context context,String message) {
		ProgressDialog pdialog = new ProgressDialog(context);
		pdialog.setTitle("爱游戏");
		pdialog.setMessage(message);
		pdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		pdialog.show();
		pdialog.setOnKeyListener(new OnKeyListener() {

			@Override
			public boolean onKey(DialogInterface dialog, int keyCode,
					KeyEvent event) {
				switch (event.getKeyCode()) {
				case KeyEvent.KEYCODE_BACK:
					return true;
				}
				return false;
			}
		});
		return pdialog;
	}

	/*
	 * 网络交互完毕，取消Dialog
	 */
	public static void closeDialog(ProgressDialog pdialog) {
		pdialog.cancel();
	}

}
